#include <iostream>
using namespace std;
#include <stdio.h>
char * sort_chars(char *in_array, const char *rule)
{
	int flags[256]={0};
	int i,j, src_len, rule_len;
	src_len  = (int)strlen(in_array);
	rule_len = (int)strlen(rule);
	for(i=0; i<src_len; ++i)
	{
		flags[in_array[i]]++;
	}
	for(i=0,j=0; i<rule_len; ++i)
	{
		while(flags[rule[i]]-->0)
			in_array[j++] = rule[i];
	}
	return in_array;
}
//int main( void )
//{
//	char array[]="abc";
//	const char *rule = "cfadbe";
//	printf("Before sort, chars are %s\n", array);
//	sort_chars(array, rule);
//	printf("After sort, chars are %s\n", array);
//	return 0;
//}
